function modifyStyleTsForm(style: any) {
  if (!style) return style;
  const newStyle = { ...(style || {}) };

  if (!Number.isNaN(style.x) || !Number.isNaN(style.y)) {
    newStyle.transform = `translate(${Math.floor(style.x)}px,${Math.floor(style.y)}px)`;
    if (style.w !== null) {
      newStyle.width = `${Math.floor(style.w)}px`;
    }
    if (style.h !== null) {
      newStyle.height = `${Math.floor(style.h)}px`;
    }
  }
  delete newStyle.y;
  delete newStyle.x;
  delete newStyle.w;
  delete newStyle.h;
  return newStyle;
}

function getCurrentNodeByEvent(e:any, tempInterval: number = 0, filterFn:any, store:any) {
  const opNodeList = store.getOpNodeList()
  let _currentNodeArr = opNodeList
    .filter((node:any) => {
      console.log(node)
      const pos = node.dom.current.getBoundingClientRect()
      console.log(pos)
      if (
        !(
          e.clientY <= pos.y + pos.height + tempInterval &&
          e.clientX <= pos.x + pos.width + tempInterval &&
          e.clientY >= pos.y - tempInterval &&
          e.clientX >= pos.x - tempInterval
        )
      ) {
        return false;
      }
      if (!filterFn(node)) return false;
      return true
    })
  if (_currentNodeArr.length) {
    return _currentNodeArr[_currentNodeArr.length-1];
  }
  return null;
}

export default {
  modifyStyleTsForm,
  getCurrentNodeByEvent
}